#include "UButton.h"
#include "../UControlContainerWindow.h"

void* LastControlClicked;

bool TControl::IsFocussed()
{
	return HasFocus;
}

TControl::TControl(TRectangle rect)
{
	Left = rect.Left;
	Top = rect.Top;
	Right = rect.Right;
	Bottom = rect.Bottom;
	visible = true;
	LastClickWasOurs = false;
	MouseOver = false;
	HasFocus = false;
}

bool TControl::Contains(int X, int Y)
{
	return
	(Left<=X  ) &&
	(X<=Right ) &&
	(Top<=Y  ) &&
	(Y<=Bottom);
}

TRectangle TControl::BoundsRect()
{
	return TRectangle(Left, Top, Right, Bottom);
}

void TControl::MouseMove(int X, int Y, int mstate)
{
    MouseOver = true;
	LastMX = X;
	LastMY = Y;
    //printf("TControl::MouseMove()");    
}

void TControl::MouseDown(int X, int Y, uint8 button)
{
	LastClickWasOurs = true;
}

void TControl::MouseUp(int X, int Y, uint8 button)
{
	if (LastClickWasOurs && Contains(X, Y))
		this->MouseClick();
	LastClickWasOurs = false;
}

void TControl::MouseLeave()
{
    MouseOver = false;
    //printf("TControl::MouseLeave()");
}

void TControl::MouseClick()
{
}

void TControl::KeyDown(SDL_KeyboardEvent* Key)
{
}

void TControl::KeyUp(SDL_KeyboardEvent* Key)
{
}

void TControl::setFocus(bool focus)
{
	HasFocus = focus;
}

void TControl::setPos(TRectangle rect)
{
	Left = rect.Left;
	Top = rect.Top;
	Right = rect.Right;
	Bottom = rect.Bottom;
}
